<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Optimist Racing: C:/Users/Owner/My Programming/Personal Projects/VideoGames/Optimist Racing/src/Grid.hpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">Optimist Racing
   &#160;<span id="projectnumber">0.1</span>
   </div>
   <div id="projectbrief">A video game where you must literally keep your head up</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.2 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('_grid_8hpp_source.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Grid.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_grid_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/*  Copyright (C) 2012  Claude Richard</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> *  This program is free software: you can redistribute it and/or modify</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> *  it under the terms of the GNU General Public License as published by</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> *  the Free Software Foundation, either version 3 of the License, or</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> *  (at your option) any later version.</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"> *  This program is distributed in the hope that it will be useful,</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment"> *  but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"> *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"> *  GNU General Public License for more details.</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment"> *  You should have received a copy of the GNU General Public License</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment"> *  along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;</div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="preprocessor">#pragma once</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="preprocessor"></span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="keyword">template</span>&lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00026"></a><span class="lineno"><a class="code" href="class_grid2_d.html">   26</a></span>&#160;<span class="keyword">class </span><a class="code" href="class_grid2_d.html" title="A 2d grid where each cell has a value.">Grid2D</a></div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;{</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;    </div>
<div class="line"><a name="l00047"></a><span class="lineno"><a class="code" href="class_grid2_d.html#a2d0de43afc44cfa9b1f85e2a89407987">   47</a></span>&#160;    <a class="code" href="class_grid2_d.html#a2d0de43afc44cfa9b1f85e2a89407987" title="Basic constructor.">Grid2D</a>( <span class="keywordtype">double</span> originX, <span class="keywordtype">double</span> originY, <span class="keywordtype">int</span> numCellsX, <span class="keywordtype">int</span> numCellsY, <span class="keywordtype">double</span> gridHX, <span class="keywordtype">double</span> gridHY, T* values )</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;        : mOriginX( originX )</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;        , mOriginY( originY )</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;        , mNumCellsX( numCellsX )</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;        , mNumCellsY( numCellsY )</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;        , mGridHX( gridHX )</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;        , mGridHY( gridHY )</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;    {</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;        mValues = <span class="keyword">new</span> T[mNumCellsX*mNumCellsY];</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;mNumCellsX; i++) {</div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;            <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j=0; j&lt;mNumCellsY; j++) {</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;                mValues[ i + j*mNumCellsX ] = values[ i + j*mNumCellsX ];</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;            }</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;        }</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;    }</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;    </div>
<div class="line"><a name="l00067"></a><span class="lineno"><a class="code" href="class_grid2_d.html#a882eef0c27a9c0dc379254633f6b4632">   67</a></span>&#160;    <a class="code" href="class_grid2_d.html#a882eef0c27a9c0dc379254633f6b4632" title="The destructor.">~Grid2D</a>()</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;    {</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;        <span class="keyword">delete</span>[] mValues;</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;    }</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;    </div>
<div class="line"><a name="l00076"></a><span class="lineno"><a class="code" href="class_grid2_d.html#a297945ebee6053b879eb2302fb997257">   76</a></span>&#160;    <span class="keywordtype">double</span> <a class="code" href="class_grid2_d.html#a297945ebee6053b879eb2302fb997257" title="Returns the x-value of the origin of the grid (bottom-left corner).">getOriginX</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> mOriginX; };</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;</div>
<div class="line"><a name="l00082"></a><span class="lineno"><a class="code" href="class_grid2_d.html#ae84fe7442dccef0d49eedc65fe96b06a">   82</a></span>&#160;    <span class="keywordtype">double</span> <a class="code" href="class_grid2_d.html#ae84fe7442dccef0d49eedc65fe96b06a" title="Returns the y-value of the origin of the grid (bottom-left corner).">getOriginY</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> mOriginY; };</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;</div>
<div class="line"><a name="l00088"></a><span class="lineno"><a class="code" href="class_grid2_d.html#a93655a3d92f6f98eeb6ec5826cd89249">   88</a></span>&#160;    <span class="keywordtype">double</span> <a class="code" href="class_grid2_d.html#a93655a3d92f6f98eeb6ec5826cd89249" title="Returns the x-spacing of the grid (the width of each cell).">getGridHX</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> mGridHX; };</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;</div>
<div class="line"><a name="l00094"></a><span class="lineno"><a class="code" href="class_grid2_d.html#a23b8af0f8e33c530bd1afbc5c77c50e2">   94</a></span>&#160;    <span class="keywordtype">double</span> <a class="code" href="class_grid2_d.html#a23b8af0f8e33c530bd1afbc5c77c50e2" title="Returns the y-spacing of the grid (the height of each cell).">getGridHY</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> mGridHY; };</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;</div>
<div class="line"><a name="l00100"></a><span class="lineno"><a class="code" href="class_grid2_d.html#a2b6c57bd0364ec5ec86ac5adf84bcbc5">  100</a></span>&#160;    <span class="keywordtype">int</span> <a class="code" href="class_grid2_d.html#a2b6c57bd0364ec5ec86ac5adf84bcbc5" title="Returns the number of cells across the x-direction.">getNumCellsX</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> mNumCellsX; };</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;</div>
<div class="line"><a name="l00106"></a><span class="lineno"><a class="code" href="class_grid2_d.html#aaa3fd3dbe8e175ae01bf51af3dac72bc">  106</a></span>&#160;    <span class="keywordtype">int</span> <a class="code" href="class_grid2_d.html#aaa3fd3dbe8e175ae01bf51af3dac72bc" title="Returns the number of cells across the y-direction.">getNumCellsY</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> mNumCellsY; };</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;    </div>
<div class="line"><a name="l00117"></a><span class="lineno"><a class="code" href="class_grid2_d.html#a35171b27de35bf8ea47437e35a06ada7">  117</a></span>&#160;    T <a class="code" href="class_grid2_d.html#a35171b27de35bf8ea47437e35a06ada7" title="Returns the value at the cell number [i,j].">getValue</a>( <span class="keywordtype">int</span> i, <span class="keywordtype">int</span> j, T defaultValue )<span class="keyword"> const</span></div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;<span class="keyword">    </span>{</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;        <span class="keywordflow">if</span> (i&lt;0 || j&lt;0 || i&gt;=mNumCellsX || j&gt;=mNumCellsY) {</div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;            <span class="keywordflow">return</span> defaultValue;</div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;        }</div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;        <span class="keywordflow">return</span> mValues[ mNumCellsX * j + i ];</div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;    }</div>
<div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;    </div>
<div class="line"><a name="l00134"></a><span class="lineno"><a class="code" href="class_grid2_d.html#aa40e58a8322d1abf80f7479cc86f7dda">  134</a></span>&#160;    T <a class="code" href="class_grid2_d.html#a35171b27de35bf8ea47437e35a06ada7" title="Returns the value at the cell number [i,j].">getValue</a>( <span class="keywordtype">double</span> x, <span class="keywordtype">double</span> y, T defaultValue )<span class="keyword"> const</span></div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;<span class="keyword">    </span>{</div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;        <span class="keywordtype">int</span> floox = floor(x/mGridHX);</div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;        <span class="keywordtype">int</span> flooy = floor(y/mGridHY);</div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;        <span class="keywordflow">return</span> <a class="code" href="class_grid2_d.html#a35171b27de35bf8ea47437e35a06ada7" title="Returns the value at the cell number [i,j].">getValue</a>( floox, flooy, defaultValue );</div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;    }</div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;</div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;<span class="keyword">private</span>:</div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;    </div>
<div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;    <span class="keywordtype">double</span> mOriginX;</div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;    </div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;    <span class="keywordtype">double</span> mOriginY;</div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;    </div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;    <span class="keywordtype">double</span> mGridHX;</div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;    </div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;    <span class="keywordtype">double</span> mGridHY;</div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;    </div>
<div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;    <span class="keywordtype">int</span> mNumCellsX;</div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;    </div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;    <span class="keywordtype">int</span> mNumCellsY;</div>
<div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;    </div>
<div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;    T* mValues;</div>
<div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;};</div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="_grid_8hpp.html">Grid.hpp</a></li>
    <li class="footer">Generated on Sun Oct 28 2012 13:14:14 for Optimist Racing by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.2 </li>
  </ul>
</div>
</body>
</html>
